package com.ybliang.plat.serviceapp.common.exception;

/**
 * 基础错误码，所有content服务共用
 * 可扩展自定义
 * @author liangyb1
 */
public final class Errors {

    /**
     * 系统类错误 - 99 ======= [99000, 99999]
     */
    public enum SystemError implements Error {

        //======= 系统类错误 - 99 ======= [99000, 99999]
        SYS_ERROR           (99000, "system error"),
        IN_PROCESS          (99001, "system is being processed"),
        IN_LIMITED          (99002, "overflow"),
        MISS_TOKEN          (99003, "miss token"),
        ACCESS_DENIED       (99004, "access denied");

        public int code;
        public String msg;
        private SystemError(int code, String msg) { this.code = code; this.msg = msg; }

        @Override
        public int getCode() { return code; }

        @Override
        public String getMessage() {  return msg; }
    }

    /**
     * 校验类错误 - 21 ======= [21000, 21999]
     */
    public enum CheckError implements Error {
        // 校验非法（此异常未指明具体何种校验，慎用） 一级错误
        CHECK_INVALID_ERROR     (21000, "check invalid error"),
        // http参数校验错误 - 210 [21001, 21099]
        PARAM_NOT_NULL_ERROR    (21001, "param not null error"),
        PARAM_CAST_ERROR        (21002, "param cast error"),

        BAD_REQUEST_400         (21400, "bad request 400"),
        // 参数校验错误 - 214 [21401, 21499]    - 对应http code 4xx
        BAD_REQUEST_403         (21403, "bad request 403"),
        BAD_REQUEST_404         (21404, "bad request 404"),

        // 参数校验错误 - 215 [21501, 21599]    - 对应http code xxx
        BAD_REQUEST_503         (21503, "bad request 503"),
        BAD_REQUEST_504         (21504, "bad request 504"),

        // 鉴权不通过 错误 - 216 [21601, 21699]    - 对应鉴权类错误
        TOKEN_VERFIED_ERROR     (21601, "token verfied error"),
        TOKEN_VERFIED_FAILED    (21602, "token verfied failed"),
        TOKEN_VERFIED_TIMEOUT   (21603, "token verfied timeout"),

        // Session校验不通过 错误 - 217 [21701, 21799]    - 对应session校验类错误
        SESSION_VERFIED_ERROR     (21701, "session verfied error"),
        SESSION_VERFIED_FAILED    (21702, "session verfied failed"),
        SESSION_VERFIED_TIMEOUT   (21703, "session verfied timeout");


        public int code;
        public String msg;
        private CheckError(int code, String msg) { this.code = code; this.msg = msg; }

        @Override
        public int getCode() { return code; }

        @Override
        public String getMessage() {  return msg; }
    }


    /**
     *  依赖服务错误 - 31 ======= [31000, 31099]
     */
    public enum DependencyError implements Error {
        // 此异常码不明不白，慎用
        CALL_DEPENDENCY_ERROR       (31000, "call dependency error"),
        // 依赖服务错误 cms - 310 [31001, 31099]
        // 调用cms异常 or cms返回500 or cms 返回200单code不为success
        CALL_CMS_ERROR              (31001, "call cms error"),
        CALL_CMS_TIMEOUT_ERROR      (31002, "call cms timeout"),
        // 调用cms成功，但解析数据出现异常,即cms返回的数据解析出问题
        CALL_CMS_RESP_PARSE_ERROR   (31003, "call cms resp parse error"),

        // 依赖服务错误 dcp - 311 [31101, 31199]
        CALL_DCP_ERROR              (31101, "call dcp error"),
        CALL_DCP_TIMEOUT_ERROR      (31102, "call dcp timeout"),
        CALL_DCP_RESP_PARSE_ERROR   (31103, "call dcp resp parse error"),

        // 依赖服务错误 health - 312 [31201, 31209]
        CALL_HEALTH_ERROR           (31201, "call health error"),
        CALL_HEALTH_TIMEOUT_ERROR   (31202, "call health timeout"),
        CALL_HEALTH_RESP_PARSE_ERROR(31303, "call health resp parse error"),

        // 依赖服务错误 interactive - 313 [31301, 31309]
        CALL_INTERACTIVE_ERROR              (31301, "call interactive error"),
        CALL_INTERACTIVE_TIMEOUT_ERROR      (31302, "call interactive timeout"),
        CALL_INTERACTIVE_RESP_PARSE_ERROR   (31303, "call interactive resp parse error"),


        // 依赖服务错误 bigdata - 314 [31401, 31409]
        CALL_BIGDATA_ERROR              (31401, "call bigdata error"),
        CALL_BIGDATA_TIMEOUT_ERROR      (31402, "call bigdata timeout"),
        CALL_BIGDATA_RESP_PARSE_ERROR   (31403, "call bigdata resp parse error");


        public int code;
        public String msg;
        private DependencyError(int code, String msg) { this.code = code; this.msg = msg; }

        @Override
        public int getCode() { return code; }

        @Override
        public String getMessage() {  return msg; }
    }


    /**
     * 调用中间件服务错误 - 13 ======= [13000, 13099]
     */
    public enum BaseError implements Error {
        // 调用中间件服务错误 es - 130 [13001, 13099]
        CALL_ES_ERROR                   (13000, "call es error"),
        CALL_ES_TIMEOUT_ERROR           (13001, "call es timeout"),
        CALL_ES_READ_ERROR              (13002, "call es read error"),
        CALL_ES_UPDATE_ERROR            (13003, "call es update error"),
        CALL_ES_DATA_NOT_EXIST_ERROR    (13004, "call es data not exist error"),

        // 调用中间件服务错误 kafka - 131 [13101, 13199]
        CALL_KAFKA_ERROR        (13101, "call kafka error"),
        CALL_KAFKA_SEND_ERROR   (13102, "call kafka send error"),

        // 调用中间件服务错误 cassandra - 132 [13201, 13299]
        CALL_CASSANDRA_ERROR        (13201, "call cassandra error"),

        // 调用中间件服务错误 redis - 133 [13301, 13399]
        CALL_REDIS_ERROR        (13301, "call redis error"),

        // 调用中间件服务错误 mysql - 134 [13401, 13499]
        CALL_MYSQL_ERROR        (13401, "call mysql error");

        public int code;
        public String msg;
        private BaseError(int code, String msg) { this.code = code; this.msg = msg; }

        @Override
        public int getCode() { return code; }

        @Override
        public String getMessage() {  return msg; }
    }

}
